using System;
using System.Web;

namespace Framework.Library.Core.Utils.Web
{
    public class MockHttpContextGetter : IHttpContextGetter
    {
        private HttpContext _context;

        #region IHttpContextGetter Members

        public HttpContext GetHttpContext()
        {
            if (_context == null)
            {
                var contextMocker = new MockHttpContext(true);
                HttpContext mockedContext = contextMocker.Context;

                if (mockedContext == null)
                    throw new Exception("Mocked HttpContext null.");

                _context = mockedContext;
            }

            return _context;
        }

        #endregion
    }
}